package com.ljl.basic.service.impl;

import com.ljl.basic.service.IBaiduAiAuditService;
import com.ljl.basic.util.BaiduAuditUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Service
public class BaiduAiAuditServiceImpl implements IBaiduAiAuditService {

    @Override
    public Boolean textAudit(String auditText) {
        //@TODO - 自主研发 - 工具类BaiduAuditUtils
        Boolean textBoo = BaiduAuditUtils.TextCensor(auditText);

        return textBoo;
    }

    /*
     *  注意:resources是这样的格式：
     *  /group1/M00/00/02/CgAIC2KevEeAX2T4AAEUusLjqqk161.png,/group1/M00/00/02/CgAIC2KevEeAX2T4AAEUusLjqqk162.png
     *  需要判断是否为空，只有一张怎么处理，有多张怎么处理
     *  需要统一加前缀：http://123.207.27.208
     */
    @Override
    public Boolean imageAudit(String resources) {
        //@TODO - 自主研发 - 工具类BaiduAuditUtils
        if (!StringUtils.isEmpty(resources)){
            String[] split = resources.split(",");
            List<String> url = new ArrayList<>();
            for (String s : split) {
                url.add("http://123.207.27.208" + s);
            }
            if (url.size() == 1){
                return BaiduAuditUtils.ImgCensor(url.get(0));
            } else {
                for (String s : url) {
                    if (!BaiduAuditUtils.ImgCensor(s)){
                        return false;
                    }
                }
            }

        }
        return true;
    }
}